﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;

public partial class LienHe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnGuiMail_Click(object sender, EventArgs e)
    {
        String to = "duytrungmac@yahoo.com";

        //string name = HtmlTextWriterAttribute . T5.Value;
        String body = String.Format("Họ tên khách hàng: {0} <br/>", T5.Value);

        body += String.Format("Email: {0} <br/>", T6.Value);
        body += String.Format("Điện thoại: {0} <br/>", T7.Value);
        body += String.Format("Địa chỉ: {0} <br/>", A8.Value);
        body += String.Format("Nội dung: {0} <br/>", A9.Value);

        String subject = "Liên hệ của khách hàng " + T5.Value;

        SendMail(to, subject, body);

        Response.Redirect("Trangchu.aspx");
    }

    public static void SendMail(string to, string subject, string body)
    {
        string from = "showroommya@gmail.com";
        string temp = "showroommya@gmail.com";
        string pwd = "showroommya.com";

        MailMessage mail = new MailMessage();
        mail.To.Add(to);
        mail.From = new MailAddress(from);
        mail.Subject = subject;
        mail.Body = body;


        mail.IsBodyHtml = true;

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.Credentials = new System.Net.NetworkCredential(temp, pwd,"");
        try
        {

            smtp.Send(mail);
        }
        catch (Exception exc) { HttpContext.Current.Response.Redirect("ReportErrorSystem.aspx"); }


    }
}
